package xyz.yuzegod.megawalls.classes.normal.squid;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Chest;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import xyz.yuzegod.megawalls.MegaWalls;
import xyz.yuzegod.megawalls.classes.Classes;
import xyz.yuzegod.megawalls.classes.CollectSkill;
import xyz.yuzegod.megawalls.game.GamePlayer;
import xyz.yuzegod.megawalls.stats.KitStatsContainer;
import xyz.yuzegod.megawalls.util.ItemBuilder;
import xyz.yuzegod.megawalls.util.ItemUtils;
import xyz.yuzegod.megawalls.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class FourthSkill extends CollectSkill
{
    public FourthSkill(final Classes classes) {
        super("海之眷顾", classes);
    }
    
    @Override
    public int maxedLevel() {
        return 3;
    }
    
    @Override
    public double getAttribute(final int level) {
        switch (level) {
            case 1: {
                return 0.15;
            }
            case 2: {
                return 0.2;
            }
            case 3: {
                return 0.25;
            }
            default: {
                return 0.15;
            }
        }
    }
    
    @Override
    public List<String> getInfo(final int level) {
        final List<String> lore = new ArrayList<String>();
        if (level == 1) {
            lore.add(" §8▪ §7有§a" + StringUtils.percent(this.getAttribute(level)) + "§7的几率在箱子中找到");
            lore.add("    §71:00伤害吸收II药水。");
            return lore;
        }
        lore.add(" §8▪ §7有§8" + StringUtils.percent(this.getAttribute(level - 1)) + " ➜");
        lore.add("    §a" + StringUtils.percent(this.getAttribute(level)) + "§7的几率在箱子中找到");
        lore.add("    §71:00伤害吸收II药水。");
        return lore;
    }
    
    @Override
    public void upgrade(final GamePlayer gamePlayer) {
        final KitStatsContainer kitStats = gamePlayer.getPlayerStats().getKitStats(this.getClasses());
        kitStats.addSkill4Level();
    }
    
    @Override
    public int getPlayerLevel(final GamePlayer gamePlayer) {
        return gamePlayer.getPlayerStats().getKitStats(this.getClasses()).getSkill4Level();
    }
    
    @Override
    public void onBlockBreak(final KitStatsContainer kitStats, final BlockBreakEvent e) {
        Bukkit.getScheduler().runTaskLater((Plugin)MegaWalls.getInstance(), (Runnable)new Runnable() {
            @Override
            public void run() {
                if (ItemUtils.matchMaterial(e.getBlock() ,Material.TRAPPED_CHEST) && MegaWalls.getRandom().nextInt(250) <= FourthSkill.this.getAttribute(kitStats.getSkill4Level()) * 100.0) {
                    final Chest chest = (Chest)e.getBlock().getState();
                    final ItemBuilder itemBuilder = new ItemBuilder(Material.POTION, 1, (byte)69).setDisplayName("§b1:00伤害吸收II");
                    itemBuilder.addPotion(new PotionEffect(PotionEffectType.ABSORPTION, 1200, 1));
                    chest.getBlockInventory().addItem(itemBuilder.build());
                }
            }
        }, 3L);
    }
}
